import 'package:amap_flutter_base/amap_flutter_base.dart';
import 'package:amap_flutter_map/amap_flutter_map.dart';
import 'package:flutter/material.dart';

class Choice extends StatefulWidget {
  // Choice({Key key}) : super(key: key);

  @override
  _ChoiceState createState() => _ChoiceState();
}

class _ChoiceState extends State<Choice> {
  CameraPosition _kInitialPosition = const CameraPosition(
    target: LatLng(39.909187, 116.397451),
    zoom: 16.0,
  );

  final Map<String, Marker> _initMarkerMap = <String, Marker>{};

  Object _mapController = Object();
  void onMapCreated(AMapController controller) {
    setState(() {
      _mapController = controller;
    });
  }

  @override
  Widget build(BuildContext context) {
    Marker marker = Marker(position: LatLng(39.909187, 116.397451), draggable: true, onDragEnd: (id, latLng){
      print('拖拽结果');
      print(id);
      print(latLng);
    });
    _initMarkerMap[marker.id] = marker;

    final AMapWidget map = AMapWidget(
      initialCameraPosition: _kInitialPosition,
      onMapCreated: onMapCreated,
      myLocationStyleOptions: MyLocationStyleOptions(
        true,
      ),
      markers: Set<Marker>.of(_initMarkerMap.values),
      onCameraMove: (argument) {
        print('onCameraMove...');
        print(argument);
      },
    );

    return Scaffold(
      appBar: AppBar(
        title: Text('地图选点'),
      ),
      body: Container(
        height: MediaQuery.of(context).size.height,
        width: MediaQuery.of(context).size.width,
        child: map,
      ),
    );
  }
}
